var maxSubarraySumCircular = function (nums) {
  let dp = [];
  dp[0] = nums[0];
  let max = dp[0];
  let sum = dp[0];
  for (let i = 1; i < nums.length; i++) {
    sum = sum + nums[i];
    dp[i] = dp[i - 1] > 0 ? dp[i - 1] + nums[i] : nums[i];
    max = Math.max(max, dp[i]);
  }
  console.log(sum);

  console.log(dp);

  let min = 0;
  dp[0] = nums[0];
  for (let i = 1; i < nums.length - 1; i++) {
    dp[i] = dp[i - 1] < 0 ? dp[i - 1] + nums[i] : nums[i];
    min = Math.min(dp[i], min);
  }
  console.log(min, max);

  return Math.max(sum - min, max);
};
let arr = [1, 2, 3, -2, -1];
let res = maxSubarraySumCircular(arr);
console.log(res);
